package cn.itcast.controller;


import cn.itcast.domain.Catalog;
import cn.itcast.service.CatalogService;
import cn.itcast.service.impl.CatalogServiceImpl;
import com.github.pagehelper.PageInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/store/catalog/*")
public class CatalogServlet extends BaseServlet {
    private CatalogService catalogService = new CatalogServiceImpl();
    // TODO: 时间   ********  查询所有功能  *********
    protected void findAll(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String page =  req.getParameter("page");
        int pageNum = 1;
        if (page!=null && !page.equals("")){
            pageNum = Integer.parseInt(page);
        }
        List<Catalog> catalogList =  catalogService.findAll(pageNum);

        PageInfo<Catalog> pageInfo = new PageInfo<Catalog>(catalogList);
        req.setAttribute("page",pageInfo);
        req.getRequestDispatcher("/pages/catalog/list.jsp").forward(req,resp);

    }

}
